package com.kairos.engine
{
	import flexunit.framework.TestCase;

	public class RTObjectTest extends TestCase
	{
		private var _oB : MockRTBeacon;
		private var _o : MockRTObject;
		
		public override function setUp () : void
		{
			_oB = MockRTBeacon.getInstance();
			_o = new MockRTObject ();
		}
		
		public function testConstruct () : void
		{
			assertNotNull ( "MockRTObject constructor returns null" , _o );
		}
		
		public function testStartStop() : void
		{
			_oB.onTick( null );
			
			assertFalse ( _o + " have been called while it was not started", _o.called );
			
			_o.start ();
			
			_oB.onTick( null );
			assertTrue( _o + " haven't been called while it was started", _o.called );
			assertTrue( _o + ".isRunning() return false after a call of start", _o.isRunning() );
			
			_o.called = false;
			_o.stop ();
			
			assertFalse( _o + ".isRunning() return true after a call of sop", _o.isRunning() );
			
			_oB.onTick( null );
			assertFalse ( _o + " have been called while it was stoped", _o.called );
		}
		
		public function testStartAlias () : void
		{
			_o.execute ();
			assertTrue( _o + ".isRunning() return false after a call of execute", _o.isRunning() );
			_o.stop ();
			
			_o.play ();
			assertTrue( _o + ".isRunning() return false after a call of play", _o.isRunning() );
			_o.stop ();
		}
		public function testLocalSpeedGetterSetter () : void 
		{
			var errorOccurs : Boolean;
			
			errorOccurs = false;
			try
			{
				_o.setLocalSpeed( 0 );
			}
			catch ( e : Error )
			{
				errorOccurs = true;
			}
			
			assertTrue( _o + ".setLocalSpeed() don't failed with a value of 0", errorOccurs );
			assertEquals ( _o + ".setLocalSpeed() with an invalid argument have modify the local speed", 1, _o.getLocalSpeed() );
			
			errorOccurs = false;
			try
			{
				_o.setLocalSpeed( -1 );
			}
			catch ( e : Error )
			{
				errorOccurs = true;
			}
			
			assertTrue( _o + ".setLocalSpeed() don't failed with a negative value", errorOccurs );
			assertEquals ( _o + ".setLocalSpeed() with an invalid argument have modify the local speed", 1, _o.getLocalSpeed() );
			
			
			_o.setLocalSpeed( 2 );
			assertEquals ( _o + ".setLocalSpeed() failed to change the local speed", 2, _o.getLocalSpeed() );
			
		}
		public function testTickBeaconGetterSetter () : void 
		{
			var errorOccurs : Boolean;
			
			errorOccurs = false;
			try
			{
				_o.setTickBeacon( null );
			}
			catch ( e : Error )
			{
				errorOccurs = true;
			}
			
			assertTrue( _o + ".setTickBeacon() don't failed with a null beacon", errorOccurs );
			
			var beacon : MockRTBeacon = new MockRTBeacon ();
			
			_o.setTickBeacon( beacon );
			
			assertEquals ( _o + ".setTickBeacon() failed to set the new beacon", beacon, _o.getTickBeacon() );
		}
	}
}